//
//  ApiPath.swift
//  Core
//
//  Created by raymond Peng on 2018/11/9.
//  Copyright © 2018 raymond Peng. All rights reserved.
//

import Foundation

enum TBServerResource {
    case api(path: ApiPaths)
    case pay
    case web
    case blog

    var url: URL? {
        switch self {
        case .api(let path):
            let base: String
            #if DEBUG
            base = "http://api.tanbaye.com"
            #else
            base = "https://api.tanbaye.com"
            #endif
            return URL(string: base + path.rawValue)
        default:
            return nil
        }
    }
}

enum ApiPaths: String {
    case shoppingData = "/shop/api/scGoods/getGoodsList"
}

func getURL(_ resourceType: TBServerResource) -> URL? {
    switch resourceType {
    case .api(let path):
        let base: String
        #if DEBUG
        base = "http://api.tanbaye.com"
        #else
        base = "https://api.tanbaye.com"
        #endif
        return URL(string: base + path.rawValue)
    default:
        return nil
    }
}
